package whu.o2o.adapter;

import java.util.ArrayList;

import whu.o2o.vo.StudioVO;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import whu.o2o.R;

public class StudioAdapter extends BaseAdapter {
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	private ArrayList<StudioVO> mList;

	public StudioAdapter(Context context, ArrayList<StudioVO> list) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(mContext);
		mList = list;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		StudioVO studioVO = mList.get(position);

		ViewHolder holder;
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.listitem_studio, null);

			holder = new ViewHolder();
			holder.head = (ImageView) convertView.findViewById(R.id.head);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.peopleCount = (TextView) convertView.findViewById(R.id.people_count);
			holder.focusedCount = (TextView) convertView.findViewById(R.id.focused_count);
			holder.label = (TextView) convertView.findViewById(R.id.label);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.name.setText(studioVO.getName());
		holder.peopleCount.setText(String.format(mContext.getResources().getString(R.string.studio_people),
				studioVO.getPeopleCount()));
		holder.focusedCount.setText(String.format(mContext.getResources().getString(R.string.studio_focused),
				studioVO.getFocusedCount()));
		holder.label.setText(studioVO.getLabel());

		return convertView;
	}

	static class ViewHolder {
		ImageView head;
		TextView name;
		TextView peopleCount;
		TextView focusedCount;
		TextView label;

	}
}
